import React from 'react';
import './../assets/css/main';
import {observer, inject} from 'mobx-react';
import Progress from './Progress.jsx';
import http from "./../server/httpAxios.js";
import req from "./../server/apiSetting.js";
import {remote, dialog, ipcRenderer} from 'electron';

// const {dialog} = require('electron');
@inject('demoStore')
@observer
export default class App extends React.Component {
    handleRest = () => {
        this
            .props
            .demoStore
            .addNum();
    };
    openWindow = () => {
        // dialog.showOpenDialog({properties: ['openFile', 'openDirectory',
        // 'multiSelections']}); 新窗口的大小
        let win = new remote.BrowserWindow({width: 400, height: 320});
        win.on('close', function () {
            // 窗口被关闭时清空资源
            win = null
        });
        // 加载网页
        win.loadURL('http://localhost:3000/');
        // 显示窗口
        win.show();

    };
    updateApp = () => {

        ipcRenderer.send("checkForUpdate");

        ipcRenderer.on("message", (event, text) => {
            console.log(arguments);
            //_this.tips = text;
            // alert(text)
        });

        ipcRenderer.on("downloadProgress", (event, progressObj) => {
            console.log(progressObj);
            //_this.downloadPercent = progressObj.percent || 0;
        });

        ipcRenderer.on("isUpdateNow", () => {
            ipcRenderer.send("isUpdateNow");
        });
    };
    tz = () => {};
    componentWillReact() {
        console.log('数据被更新');
        http(req.get_todolist).then(res => {
            console.log(res.data);
        }, error => {
            console.log(error);
        });
        http(req.post_todo).then(res => {
            console.log(res.data);
        }, error => {
            console.log(error);
        });

    };
    render() {
        return (
            <div className={'todo-box'}>
                <div className={'todo-box-tead'}>React-Mobx-Electron</div>
                <p>数值24：{this.props.demoStore.num}</p>
                <button onClick={this.handleRest}>+10</button>
                <button onClick={this.openWindow}>打开窗口</button>
                <button onClick={this.tz}>通知</button>
                <button onClick={this.updateApp}>更新</button>
            </div>
        )
    }
}
